SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[SP_TCMOVI_BANC_Q10]                      
/*-------------------------------------------------------*/                      
/*---Empresa               OFISIS S.A.                --*/                      
/*---Cliente               CELIMA                     --*/                      
/*---Sistema               Tesoreria                  --*/                      
/*---M¢dulo                Empresa                    --*/                      
/*---Programa              FLUJO DE CAJA REAL MENSUAL      --*/                      
/*---Script                SP_TCMOVI_BANC_Q03.sql     --*/                      
/*---Nombre SP             SP_TCMOVI_BANC_Q03         --*/                      
/*---Desarrollado por      Reynaldo Menacho Luyo      --*/                      
/*---Fecha Creaci¢n        25/09/2001                 --*/                      
/*---Base Datos            SQL SERVER        --*/                      
/*---Versi¢n               2000                       --*/                      
/*---Invoca a SP                                      --*/                      
/*-------------------------------------------------------*/                      
                      
/*-------------------------------------------------------*/                      
/*---Modificado 1 por           --*/                      
/*---Fecha Modificaci¢n         --*/                       
/*---Detalle Modificaci¢n       --*/                      
/*-------------------------------------------------------*/                      
                      
/*-------------------------------------------------------*/                      
/*---Drop Proc SP_TCMOVI_BANC_Q03                      --*/                      
/*---Grant all on SP_TCMOVI_BANC_Q03 to public         --*/                       
/*---SP_TCMOVI_BANC_Q03 '01', 'DOL', 10, 2001, 11, 2001  --*/                      
/*-------------------------------------------------------*/                      
                      
--EXEC UL_TCMOVI_BANC_Q10 '01', 'WHERE 1 = 1', '', 'U', 'DOL', 1,2007               
                    
@ISCO_EMPR Varchar(2),                    
@ISCA_WHER_0001 Varchar(256),                      
@ISCA_WHER_0002 Varchar(256),                 
@ISTI_PRES TD_VC_001,                     
@ISCO_MONE TD_VC_003,                      
@INNU_MESE_INIC TD_IN_001,                      
@INNU_ANIO_INIC TD_IN_001            
/*,                      
@INNU_MESE_FINA TD_IN_001,                      
@INNU_ANIO_FINA TD_IN_001  */                    
As                      
CREATE TABLE #TWFLUJ_CAJA_Q10_1                      
 ( CO_EMPR      varchar(3) NULL,   
   DE_EMPR      varchar(100) NULL,                         
   CO_ARUB varchar(3) NULL ,    
   DE_ARUB varchar(100) NULL ,                   
   CO_RUBR varchar(3) NULL ,    
   DE_RUBR varchar(100) NULL ,                    
   CO_SUBR varchar(3) NULL ,     
   DE_SUBR varchar(100) NULL ,                  
   IM_ME01_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME02_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME03_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME04_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME05_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME06_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME07_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME08_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME09_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME10_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME11_PROY numeric(16,4) DEFAULT 0,                      
   IM_ME12_PROY numeric(16,4) DEFAULT 0,     
   IM_ME01_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME02_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME03_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME04_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME05_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME06_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME07_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME08_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME09_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME10_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME11_EJEC numeric(16,4) DEFAULT 0,                      
   IM_ME12_EJEC numeric(16,4) DEFAULT 0,                                    
   CO_BANC varchar(3) NULL ,                      
   NU_CNTA_BANC varchar(20) NULL ,                      
   DE_CNTA_BANC varchar(100) NULL ,                      
   IM_SALD_INIC numeric(16,4) DEFAULT 0,                    
   TI_DETA_EMPR  varchar(1) NULL ,                    
   TI_DETA_BANC  varchar(1) NULL )                      
                  
                      
DECLARE                      
                      
@VNNU_MESE  TD_IN_001,                      
@VNNU_ANIO  TD_IN_001,                      
@VSNU_MESE  TD_VC_002,                      
@VSNU_ANIO  VARCHAR(4),                      
@VNNU_CONT_MESE TD_IN_001,                      
@VSDE_SELE VARCHAR(6000),                      
@VSCO_EMPR VARCHAR (50),                      
@VSDE_CAMP VARCHAR(7) ,                  
@VSCO_MONE_NACI TD_VC_003,                  
@VSCO_MONE_EXTR TD_VC_003,                
@VNNU_FACT  NUMERIC(16,4),        
@VNFA_CAMB_MENS  NUMERIC(15,6)                      
                      
               
EXECUTE SP_TCMOVI_BANC_PROY_Q10 @ISCO_EMPR, @ISCO_MONE, @INNU_ANIO_INIC, @INNU_MESE_INIC, @ISTI_PRES  
  
EXECUTE SP_TCMOVI_BANC_EJEC_Q10 @ISCO_EMPR, @ISCA_WHER_0001, @ISCA_WHER_0002, @ISTI_PRES, @ISCO_MONE, @INNU_MESE_INIC, 
@INNU_ANIO_INIC                 
   
IF @ISTI_PRES = 'M'                  
	BEGIN

	SELECT T1.CO_EMPR, MAX(T1.DE_EMPR), T1.CO_ARUB, MAX(T1.DE_ARUB), T1.CO_RUBR, MAX(T1.DE_RUBR), T1.CO_SUBR, 
MAX(T1.DE_SUBR),                     
	CONVERT (INT, SUM(ISNULL(T1.IM_ME01_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME01_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_ME02_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME02_EJEC ,0))),
        CONVERT (INT, SUM(ISNULL(T1.IM_ME03_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME03_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_ME04_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME04_EJEC ,0))), 
	CONVERT (INT, SUM(ISNULL(T1.IM_ME05_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME05_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_ME06_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME06_EJEC ,0))),
        CONVERT (INT, SUM(ISNULL(T1.IM_ME07_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME07_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_ME08_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME08_EJEC ,0))), 
	CONVERT (INT, SUM(ISNULL(T1.IM_ME09_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME09_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_ME10_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME10_EJEC ,0))),
        CONVERT (INT, SUM(ISNULL(T1.IM_ME11_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME11_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_ME12_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_ME12_EJEC,0))),
        T1.CO_BANC, T1.NU_CNTA_BANC, MAX(T1.DE_CNTA_BANC), MAX(T1.TI_DETA_EMPR), MAX(T1.TI_DETA_BANC)                    
	FROM #TWFLUJ_CAJA_Q10_1 T1                          
	GROUP BY T1.CO_EMPR, T1.CO_ARUB, T1.CO_RUBR, T1.CO_SUBR, T1.CO_BANC, T1.NU_CNTA_BANC          

	END
ELSE
	BEGIN                  
	SELECT T1.CO_EMPR, MAX(T1.DE_EMPR), T1.CO_ARUB, MAX(T1.DE_ARUB), T1.CO_RUBR, MAX(T1.DE_RUBR), T1.CO_SUBR, 
MAX(T1.DE_SUBR),                     
	SUM(ISNULL(T1.IM_ME01_PROY,0)), SUM(ISNULL(T1.IM_ME01_EJEC,0)), SUM(ISNULL(T1.IM_ME02_PROY ,0)), 
SUM(ISNULL(T1.IM_ME02_EJEC ,0)),
	SUM(ISNULL(T1.IM_ME03_PROY,0)), SUM(ISNULL(T1.IM_ME03_EJEC,0)), SUM(ISNULL(T1.IM_ME04_PROY ,0)), 
SUM(ISNULL(T1.IM_ME04_EJEC ,0)),
	SUM(ISNULL(T1.IM_ME05_PROY,0)), SUM(ISNULL(T1.IM_ME05_EJEC,0)), SUM(ISNULL(T1.IM_ME06_PROY ,0)), 
SUM(ISNULL(T1.IM_ME06_EJEC ,0)), 
	SUM(ISNULL(T1.IM_ME07_PROY,0)), SUM(ISNULL(T1.IM_ME07_EJEC,0)), SUM(ISNULL(T1.IM_ME08_PROY ,0)), 
SUM(ISNULL(T1.IM_ME08_EJEC ,0)),
	SUM(ISNULL(T1.IM_ME09_PROY,0)), SUM(ISNULL(T1.IM_ME09_EJEC,0)), SUM(ISNULL(T1.IM_ME10_PROY ,0)), 
SUM(ISNULL(T1.IM_ME10_EJEC ,0)),                
	SUM(ISNULL(T1.IM_ME11_PROY,0)), SUM(ISNULL(T1.IM_ME11_EJEC,0)), SUM(ISNULL(T1.IM_ME12_PROY ,0)), 
SUM(ISNULL(T1.IM_ME12_EJEC ,0)), 
	T1.CO_BANC, T1.NU_CNTA_BANC, MAX(T1.DE_CNTA_BANC), MAX(T1.TI_DETA_EMPR), MAX(T1.TI_DETA_BANC)                    
	FROM #TWFLUJ_CAJA_Q10_1 T1                          
	GROUP BY T1.CO_EMPR, T1.CO_ARUB, T1.CO_RUBR, T1.CO_SUBR, T1.CO_BANC, T1.NU_CNTA_BANC          
	END

                      
RETURN                
                      
/********************************* FIN ***********************************/


GO
